<?php
add_filter('wpjam_basic_sub_pages', 'wpjam_basic_add_holiday_sub_page');
function wpjam_basic_add_holiday_sub_page($subs){
	$subs['wpjam-holiday']	= array('menu_title'=>'节假日设置', 	'function'=>'option');
	return $subs;
}

add_filter('wpjam_settings', 'wpjam_holiday_settings');
function wpjam_holiday_settings($wpjam_settings){
	$current_year	= date( 'Y', current_time( 'timestamp' ) );

	$sections	= array();

	for ($i=0; $i<=1; $i++) {
		$sections[$current_year] = array(
			'title'=>$current_year.'节假日', 	
			'fields'=>array(
				'holidays_'.$current_year	=> array('title'=>'节假日',	'type'=>'mu-text',	'description'=>'请填入国家法定节假日或者其他节假日。'),
				'workdays_'.$current_year	=> array('title'=>'上班日',	'type'=>'mu-text',	'description'=>'请填入周六日要上班的日期。'),
	
			) 
		);
		$current_year ++;
	}

	$wpjam_settings['wpjam-holiday']	= array('sections'	=>	$sections);

	return $wpjam_settings;
}



add_filter('wpjam-holiday_field_validate','wpjam_holiday_field_validate');
function wpjam_holiday_field_validate($wpjam_holiday){
	
	$current_year	= date( 'Y', current_time( 'timestamp' ) );

	$wpjam_holiday_new = array();

	for ($i=0; $i<=1; $i++) {	// 只要今年和明年两年的数据
		$days = $wpjam_holiday['holidays_'.$current_year];
		sort($days);
		$wpjam_holiday_new['holidays_'.$current_year] = $days;

		$days = $wpjam_holiday['workdays_'.$current_year];
		sort($days);
		$wpjam_holiday_new['workdays_'.$current_year] = $days;
		
		$current_year ++;
	}

	return $wpjam_holiday_new;
}

